"""
Case Type   : 数据库安全特性
Case Name   : guc设置enable_risky_query_detection为on_set
Create At   : 2025/9
Owner       : l1azzzy
Description :
    1、设置enable_risky_query_detection参数为on
Expect      :
    1、参数设置成功
    2、环境正常恢复
History     :
"""

import os
import unittest

from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from yat.test import Node

class SecurityConfigCase0002(unittest.TestCase):

    def setUp(self):
        self.log = Logger()
        self.log.info(f'----{os.path.basename(__file__)} start----')
        self.comsh = CommonSH('PrimaryDbUser')
        self.constant = Constant()

    def test_set_risky_query_detection_on(self):
        text = '-----step1:gs_guc设置enable_risky_query_detection为on-----'
        self.log.info(text)
        
        result = result = self.comsh.execute_gsguc('set', 
                                        self.constant.GSGUC_SUCCESS_MSG,
                                        'enable_risky_query_detection=on')
        self.assertTrue(result)

    def tearDown(self):
        text = '-----恢复enable_risky_query_detection为off-----'
        self.log.info(text)
        
        result = self.comsh.execute_gsguc('reload',
                            self.constant.GSGUC_SUCCESS_MSG,
                            'enable_risky_query_detection=off')
        self.assertTrue(result)
        self.log.info(f'----{os.path.basename(__file__)} end----')